/*
 * Created on 27.08.2008
 *
 */
/**
 * @author Emporeo
 * @web http://www.fai-communication.de/accountManager
 * @web source: http://code.google.com/p/mmo-account-manager/
 */

package acm.dao;

import javax.naming.*;
import javax.servlet.*;
import javax.sql.*;
import java.sql.*;

/**
 * @author Emporeo
 * @version 1.0
 * Returns the DataSource Connection
 */
public class ConnectionHandlerDAO {
    private ServletContext context;
    private DataSource ds;
    
    public ConnectionHandlerDAO(){
    }
    
    public Connection getDataSourceConnection(ServletContext context)throws NamingException,SQLException{
        try{
//		  Obtain our environment naming context
	    Context initCtx = new InitialContext();
	    Context envCtx = (Context)initCtx.lookup(context.getInitParameter("NamingContext"));
	    
//	     Look up our data source
	    ds = (DataSource)
	    envCtx.lookup(context.getInitParameter("DatabaseSourceName"));
//	     Allocate and use a connection from the pool
	    return ds.getConnection();
        }
        finally{

        }
        
    }

}
